<html>
<head><meta charset="utf-8"><title>Type checker change causing unexpected errors · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html">Type checker change causing unexpected errors</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="222829389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/222829389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#222829389">(Jan 15 2021 at 08:09)</a>:</h4>
<p>I have this diff:</p>
<div class="codehilite"><pre><span></span><code>diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs
index d4631c465a3..b0febd5eccb 100644
--- a/compiler/rustc_typeck/src/check/method/probe.rs
+++ b/compiler/rustc_typeck/src/check/method/probe.rs
@@ -20,7 +20,7 @@
 use rustc_infer::infer::{self, InferOk, TyCtxtInferExt};
 use rustc_middle::middle::stability;
 use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
-use rustc_middle::ty::GenericParamDefKind;
+use rustc_middle::ty::{GenericParamDefKind, TypeAndMut};
 use rustc_middle::ty::{
     self, ParamEnvAnd, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness,
 };
@@ -1111,9 +1111,16 @@ fn pick_by_value_method(
                 pick.autoderefs = step.autoderefs;

                 // Insert a `&amp;*` or `&amp;mut *` if this is a reference type:
-                if let ty::Ref(_, _, mutbl) = *step.self_ty.value.value.kind() {
-                    pick.autoderefs += 1;
-                    pick.autoref = Some(mutbl);
+                match *step.self_ty.value.value.kind() {
+                    ty::Ref(_, _, mutbl) =&gt; {
+                        pick.autoderefs += 1;
+                        pick.autoref = Some(mutbl);
+                    }
+                    ty::RawPtr(TypeAndMut { ty: _, mutbl }) =&gt; {
+                        pick.autoderefs += 1;
+                        pick.autoref = Some(mutbl);
+                    }
+                    _ =&gt; {}
                 }

                 pick
</code></pre></div>
<p>The idea is that when probing for method receivers I want to try <code>&amp;*</code> and <code>&amp;mut *</code> for pointers too (in addition to references). When I apply this diff I get unexpected errors in the libraries, like:</p>
<div class="codehilite"><pre><span></span><code>error[E0282]: type annotations needed
   --&gt; library/core/src/fmt/num.rs:234:45
    |
209 | / macro_rules! impl_Display {
210 | |     ($($t:ident),* as $u:ident via $conv_fn:ident named $name:ident) =&gt; {
211 | |         fn $name(mut n: $u, is_nonnegative: bool, f: &amp;mut fmt::Formatter&lt;&#39;_&gt;) -&gt; fmt::Result {
212 | |             // 2^128 is about 3*10^38, so 39 gives an extra byte of space
...   |
234 | |                     let d1 = (rem / 100) &lt;&lt; 1;
    | |                                             ^ cannot infer type for type `{integer}`
...   |
290 | |     };
291 | | }
    | |_- in this expansion of `impl_Display!`
...
462 | /     impl_Display!(
463 | |         i8, u8, i16, u16, i32, u32, i64, u64, usize, isize
464 | |             as u64 via to_u64 named fmt_u64
465 | |     );
    | |______- in this macro invocation

error: aborting due to previous error
</code></pre></div>
<p>Most shift expressions in that file fail with the same error. I haven't tried fixing each error to see if there are other errors in other modules.</p>
<p>Anyone know how can my change cause this error? Any tips for debugging?</p>



<a name="222864636"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/222864636" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#222864636">(Jan 15 2021 at 14:34)</a>:</h4>
<p><span class="user-mention" data-user-id="119169">@osa1</span> I have no idea what causes the error, but you could try passing -Z treat-err-as-bug to get a backtrace for where it's emitted</p>



<a name="222932165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/222932165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#222932165">(Jan 15 2021 at 22:08)</a>:</h4>
<p>Maybe it's related to the <code>.offset()</code> code later on?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">                    </span><span class="kd">let</span><span class="w"> </span><span class="n">d1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">rem</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="mi">100</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"></span>
<span class="w">                    </span><span class="kd">let</span><span class="w"> </span><span class="n">d2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">rem</span><span class="w"> </span><span class="o">%</span><span class="w"> </span><span class="mi">100</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"></span>
<span class="w">                    </span><span class="n">curr</span><span class="w"> </span><span class="o">-=</span><span class="w"> </span><span class="mi">4</span><span class="p">;</span><span class="w"></span>

<span class="w">                    </span><span class="c1">// We are allowed to copy to `buf_ptr[curr..curr + 3]` here since</span>
<span class="w">                    </span><span class="c1">// otherwise `curr &lt; 0`. But then `n` was originally at least `10000^10`</span>
<span class="w">                    </span><span class="c1">// which is `10^40 &gt; 2^128 &gt; n`.</span>
<span class="w">                    </span><span class="n">ptr</span>::<span class="n">copy_nonoverlapping</span><span class="p">(</span><span class="n">lut_ptr</span><span class="p">.</span><span class="n">offset</span><span class="p">(</span><span class="n">d1</span><span class="p">),</span><span class="w"> </span><span class="n">buf_ptr</span><span class="p">.</span><span class="n">offset</span><span class="p">(</span><span class="n">curr</span><span class="p">),</span><span class="w"> </span><span class="mi">2</span><span class="p">);</span><span class="w"></span>
<span class="w">                    </span><span class="n">ptr</span>::<span class="n">copy_nonoverlapping</span><span class="p">(</span><span class="n">lut_ptr</span><span class="p">.</span><span class="n">offset</span><span class="p">(</span><span class="n">d2</span><span class="p">),</span><span class="w"> </span><span class="n">buf_ptr</span><span class="p">.</span><span class="n">offset</span><span class="p">(</span><span class="n">curr</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">2</span><span class="p">),</span><span class="w"> </span><span class="mi">2</span><span class="p">);</span><span class="w"></span>
</code></pre></div>



<a name="222932332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/222932332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#222932332">(Jan 15 2021 at 22:09)</a>:</h4>
<p>And the change in the type-checker for raw pointer <code>self</code> receivers is causing the inference of <code>d1</code> to change, thus making it unable to infer what <code>1</code>'s type is (e.g., <code>i32</code>, <code>i64</code>, <code>u32</code>, etc.)</p>



<a name="223157572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/223157572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#223157572">(Jan 18 2021 at 19:40)</a>:</h4>
<p><span class="user-mention" data-user-id="119169">@osa1</span> Just in case you missed this ^</p>



<a name="223189348"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/223189348" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#223189348">(Jan 19 2021 at 05:44)</a>:</h4>
<p><span class="user-mention" data-user-id="307537">@Camelid</span> thanks, I'll try that.<br>
<span class="user-mention" data-user-id="232545">@Joshua Nelson</span> how do I pass <code>-Ztreat-err-as-bug</code> to stage 0 when compiling libs for stage 1?</p>



<a name="223189353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/223189353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#223189353">(Jan 19 2021 at 05:44)</a>:</h4>
<p><span class="user-mention" data-user-id="119169">@osa1</span> <code>RUSTFLAGS_BOOTSTRAP=-Ztreat-err-as-bug</code></p>



<a name="223189356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/223189356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#223189356">(Jan 19 2021 at 05:44)</a>:</h4>
<p>err sorry RUSTFLAGS_NOT_BOOTSTRAP I think</p>



<a name="223189360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/223189360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#223189360">(Jan 19 2021 at 05:44)</a>:</h4>
<p>actually I don't know what you mean by any of that staging</p>



<a name="223189361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/223189361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#223189361">(Jan 19 2021 at 05:45)</a>:</h4>
<p>what command are you running?</p>



<a name="223189440"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/223189440" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#223189440">(Jan 19 2021 at 05:46)</a>:</h4>
<p>I'm running <code>./x.py build --stage 1</code></p>



<a name="223189449"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/223189449" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#223189449">(Jan 19 2021 at 05:47)</a>:</h4>
<p>ok, RUSTFLAGS_NOT_BOOSTRAP then</p>



<a name="223189460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/223189460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#223189460">(Jan 19 2021 at 05:47)</a>:</h4>
<p>Trying now, thanks</p>



<a name="223189461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/223189461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#223189461">(Jan 19 2021 at 05:47)</a>:</h4>
<p>note I would call that the 'stage 1 compiler', not stage0</p>



<a name="223190331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/223190331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#223190331">(Jan 19 2021 at 06:04)</a>:</h4>
<p>I'm getting a backtrace now, but I also lost the original type error message, so I'm not sure if this backtrace is for the error I'm trying to understand.</p>



<a name="223190844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/223190844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#223190844">(Jan 19 2021 at 06:16)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> is there a way to see <code>rustc</code> invocation for this library file so that I can just run that command?</p>



<a name="223190850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/223190850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#223190850">(Jan 19 2021 at 06:16)</a>:</h4>
<p><span class="user-mention" data-user-id="119169">@osa1</span> hmm, probably not. you can try <code>x.py build -vv</code> but I don't think it includes all environment variables</p>



<a name="223190856"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/223190856" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#223190856">(Jan 19 2021 at 06:16)</a>:</h4>
<p>it would be much easier if you can reproduce outside the standard library</p>



<a name="223190956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/223190956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> osa1 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#223190956">(Jan 19 2021 at 06:19)</a>:</h4>
<p>But how do I build stage 1 compiler to test this outside of the standard library if I can't build the standard librar for the stage 1?</p>



<a name="223191043"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/223191043" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#223191043">(Jan 19 2021 at 06:21)</a>:</h4>
<p>you'd need to compile a <code>#[no_core]</code> program</p>



<a name="223191046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/223191046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#223191046">(Jan 19 2021 at 06:21)</a>:</h4>
<p>the compiler is already built, it's just the standard library that's missing</p>



<a name="223191099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20checker%20change%20causing%20unexpected%20errors/near/223191099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20checker.20change.20causing.20unexpected.20errors.html#223191099">(Jan 19 2021 at 06:22)</a>:</h4>
<p>hmm depending on where the error is you may be able to use just <code>#[no_std]</code>, you'd have to copy the <code>core</code> artifacts to sysroot manually though</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>